<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Login extends CI_Controller {
	function __construct(){
		parent::__construct();
		//$this->load->library('epmlogin');
	}
	/**
	 * 登录模块主函数
	
	 * @author youxu
	 * @param null
	 * @return null
	 */
	public function index(){
		include_once("CAS.php");		
		phpCAS::setDebug();
		phpCAS::client(CAS_VERSION_2_0,'cas.intra.leju.com',443,'');
		phpCAS::setNoCasServerValidation();
		//$auth = phpCAS::checkAuthentication();
		$auth = phpCAS::forceAuthentication();
		if($auth)
		{

			$_SESSION["username"] =$username= strtolower(phpCAS::getUser());
			$this->load->model('user_m');
			$this->user_m->update_logintime($username);//更新登录时间
			//se_create ( array ("epm_username" => $_SESSION["username"]) );
			$url=site_url()."/admin";
			header ( "location:".$url."" );
		}
		else
		{
			phpCAS::forceAuthentication();
		}
	}
	/**
	 * 用户登陆验证
	 */
	 
	function chklogin() {
		if (! isset ( $_POST ) or empty ( $_POST ['username'] ) or empty ( $_POST ['password'] )) {
			echo "Hello";
			header ( "location:index.php" );
			exit ();
		}

		$username = $_POST ['username'];
		$password = $_POST ['password'];

	//	$this->load->model ( 'epmuser', 'user' );
	//if($this->user->auth($username, $password)){
		if (TRUE) {
			se_create( array ("epm_username" => $username, "password" => $password ) );

			header ( "location:/index.php/main/epm_index" );
			exit ();
		} else {
			header ( "location:/index.php" );
			exit ();
		}
	}
	/**
	 * 退出系统
	 * @author youxu
	 * @param null
	 * @return null
	 */
	public function logout(){
		se_destroy();
		#header('location:'.$this->config->item('logouturl'));
		include_once("CAS.php");

		phpCAS::setDebug();

		phpCAS::client(CAS_VERSION_2_0,'cas.intra.leju.com',443,'');
		phpCAS::setNoCasServerValidation();
		//phpCAS::forceAuthentication();
		phpCAS::logoutWithRedirectService(site_url().'/login/');
	}
	
}
?>